package com.edu.base.ums.umsMember.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.edu.base.ums.umsMember.domain.UmsMember;
import com.edu.base.ums.umsMember.service.IUmsMemberRyService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 会员Controller
 * 
 * @author lzs
 * @date 2021-02-21
 */
@Api("会员管理")
@RestController
@RequestMapping("/cls/umsMember")
public class UmsMemberRyController extends BaseController
{
    @Autowired
    private IUmsMemberRyService umsMemberRyService;
    

   
    
    

    /**
     * 查询会员列表
     */
    @PreAuthorize("@ss.hasPermi('cls:umsMember:list')") 
    @GetMapping("/list")
    public TableDataInfo list(UmsMember umsMemberRy)
    {
        startPage();
        List<UmsMember> list = umsMemberRyService.selectUmsMemberRyList(umsMemberRy);
        return getDataTable(list);
    }

    /**
     * 导出会员列表
     */
    @PreAuthorize("@ss.hasPermi('cls:umsMember:export')")
    @Log(title = "会员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UmsMember umsMemberRy)
    {
        List<UmsMember> list = umsMemberRyService.selectUmsMemberRyList(umsMemberRy);
        ExcelUtil<UmsMember> util = new ExcelUtil<UmsMember>(UmsMember.class);
        return util.exportExcel(list, "umsMember");
    }

    /**
     * 获取会员详细信息
     */
    @PreAuthorize("@ss.hasPermi('cls:umsMember:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(umsMemberRyService.selectUmsMemberRyById(id));
    }

    /**
     * 新增会员
     */
    @PreAuthorize("@ss.hasPermi('cls:umsMember:add')")
    @Log(title = "会员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UmsMember umsMemberRy)
    {
        return toAjax(umsMemberRyService.insertUmsMemberRy(umsMemberRy));
    }

    /**
     * 修改会员
     */
    @PreAuthorize("@ss.hasPermi('cls:umsMember:edit')")
    @Log(title = "会员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UmsMember umsMemberRy)
    {
        return toAjax(umsMemberRyService.updateUmsMemberRy(umsMemberRy));
    }

    /**
     * 删除会员
     */
    @PreAuthorize("@ss.hasPermi('cls:umsMember:remove')")
    @Log(title = "会员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(umsMemberRyService.deleteUmsMemberRyByIds(ids));
    }
    
    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('cls:umsMember:edit')")
    @Log(title = "会员管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeUmsMemberStatus")
    public AjaxResult changeUmsMemberStatus(@RequestBody  UmsMember umsMemberRy)
    {
    	umsMemberRy.setUpdateBy(String.valueOf(SecurityUtils.getLoginUser().getUser().getUserId()));
        return toAjax(umsMemberRyService.updateUmsMemberRy(umsMemberRy));
    }
    
    

    
}
